// 用户相关请求模块

import request from '@/plugins/axios.js';

export const login = (data) => {
  return request({
    method: 'post',
    url: '/v1_0/authorizations',
    data,
  });
};

// 发送验证码
// 注意：每个手机号每分钟1次
export const sendSms = (mobile) => {
  return request({
    method: 'get',
    url: `/v1_0/sms/codes/${mobile}`,
  });
};

// 获取用户自己的信息
export const getUserInfo = () => {
  return request({
    method: 'get',
    url: '/v1_0/user',
    needToken: true,
  });
};

// 获取用户频道列表
export const getUserChannels = () => {
  return request({
    method: 'get',
    url: '/v1_0/user/channels',
    needToken: true,
  });
};

// 关注用户
export const addFollow = (id) => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target: id,
    },
    needToken: true,
  });
};

// 取消关注用户
export const deleteFollow = (target) => {
  return request({
    method: 'DELETE',
    url: `/v1_0/user/followings/${target}`,
    needToken: true,
  });
};

// 获取用户个人资料
export const getUserProfile = (target) => {
  return request({
    method: 'get',
    url: '/v1_0/user/profile',
    needToken: true,
  });
};

// 修改用户个人资料
export const updateUserProfile = (data) => {
  console.log(data);
  return request({
    method: 'PATCH',
    url: '/v1_0/user/profile',
    data,
    needToken: true,
  });
};

// 修改用户照片资料
export const updateUserPhoto = (data) => {
  console.log(data);
  return request({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data,
    needToken: true,
  });
};
